﻿Public Class FormNG
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Public usr As String
    Public ty As String
    Public origin As String
    Public current_procedure_No As Integer
    Public current_procedure_Name As String
    Public txt_num_enabled As Boolean

    Dim objGtProcedure As New clsGtProcedure

    Public b_gt_procedure_operated_details_sys_id As String
    Public b_gt_sys_id As String
    Public oper_type As String
    Public oper_type_name As String
    Public type_value As String
    Public batch_no As String
    Public oper_num As String
    Public assist_marker As String
    Dim objReasonMst As New clsReasonMst
    Dim objGtProcedureOperatedNgDetails As New clsGtProcedureOperatedNgDetails
    Private Sub FormNG_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Text = current_procedure_Name & Me.Text
        If current_procedure_No > 0 Then
            lbl_operable_num.Text = "已入料数量"
            txt_oper_type_name.Text = oper_type_name
            txt_type_value.Text = type_value
            txt_batch_no.Text = batch_no
            txt_operable_num.Value = oper_num
            txt_assist_marker.Text = assist_marker
            lbl_gt_sys_id.Text = b_gt_sys_id
            lbl_gt_procedure_operated_details_sys_id.Text = b_gt_procedure_operated_details_sys_id
        Else
            lbl_operable_num.Text = "未入料数量"
            Dim dt As DataTable = objGtProcedure.getGtProcedure(ty, "'0','1'")
            dt.Columns.Add("oper_type_name")
            If dt.Rows.Count > 0 Then
                For Each row As DataRow In dt.Rows
                    If row("oper_type") = "0" Then
                        row("oper_type_name") = "骨架板"
                    Else
                        row("oper_type_name") = "法兰板"
                    End If
                Next
            End If
            If dt.Rows.Count > 0 Then
                txt_oper_type_name.Text = dt.Rows(0)("oper_type_name")
                txt_type_value.Text = dt.Rows(0)("type_value")
                txt_batch_no.Text = dt.Rows(0)("batch_no")
                txt_operable_num.Value = Integer.Parse(dt.Rows(0)("operable_num"))
                txt_num.Value = txt_operable_num.Value
                lbl_gt_sys_id.Text = dt.Rows(0)("b_gt_sys_id")
                lbl_gt_procedure_operated_details_sys_id.Text = 0
            End If
        End If
        txt_num.Enabled = txt_num_enabled
        chkNg_Reason.Items.Clear()
        If String.IsNullOrEmpty(txt_type_value.Text.Trim()) = False Then
            If oper_type.Equals("0") Then
                objReasonMst.setMstChkList(chkNg_Reason, "gjb", current_procedure_No)
            Else
                objReasonMst.setMstChkList(chkNg_Reason, "flb", current_procedure_No)
            End If
        End If
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If Integer.Parse(txt_num.Value) > 0 Then
            If Integer.Parse(txt_num.Value) <= Integer.Parse(txt_operable_num.Value) Then
                Dim chklstChecked As Boolean = False
                For i As Integer = 0 To chkNg_Reason.Items.Count - 1
                    If chkNg_Reason.Items(i).CheckState = CheckState.Checked Then
                        chklstChecked = True
                    End If
                Next
                If chklstChecked = False Then
                    MsgBox("请选择不合格原因！")
                    chkNg_Reason.Select()
                    Exit Sub
                End If
                Dim ng_reason As String = String.Empty
                For i As Integer = 0 To chkNg_Reason.Items.Count - 1
                    If chkNg_Reason.Items(i).CheckState = CheckState.Checked Then
                        ng_reason &= chkNg_Reason.Items(i).Value & "/"
                    End If
                Next
                ng_reason = ng_reason.Substring(0, ng_reason.Length - 1)
                Dim en As New entity_gt_procedure_operated_ng_details
                en.procedure_No = current_procedure_No
                en.ng_num = Integer.Parse(txt_num.Value)
                en.ng_reason = ng_reason
                en.validity = "1"
                en.oper = usr
                en.b_gt_sys_id = Integer.Parse(lbl_gt_sys_id.Text)
                en.b_gt_procedure_operated_details_sys_id = Integer.Parse(lbl_gt_procedure_operated_details_sys_id.Text)
                Dim rtn As Integer = objGtProcedureOperatedNgDetails.save(en)
                If rtn <> -2 Then
                    MsgBox("保存成功")
                    If origin = "processed" Then
                        CType(Owner, FormProcessed).setDgvData()
                    End If
                    If origin = "check" Then
                        CType(Owner, FormCheck).setDgvData()
                    End If
                    Close()
                Else
                    MsgBox("保存失败")
                End If
            Else
                If current_procedure_No > 0 Then
                    MsgBox("不合格数＞已入料数！")
                Else
                    MsgBox("不合格数＞未入料数！")
                End If
            End If
        Else
            MsgBox("不合格数量需>0")
        End If
    End Sub

    Private Sub txt_num_MouseDown(sender As Object, e As MouseEventArgs) Handles txt_num.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()
    End Sub
End Class

Public Class entity_gt_procedure_operated_ng_details
    Public procedure_No As String   ' 工序
    Public ng_num As Integer   ' 不合格数量
    Public ng_reason As String  '原因
    Public oper As String   '操作员
    Public validity As String  '有效性
    Public b_gt_procedure_operated_details_sys_id As Integer  '关联ID
    Public b_gt_sys_id As Integer  '关联ID
End Class
